<?php

$__FILEPATH__ = dirname(__FILE__)."/";
require_once($__FILEPATH__."../func_common.php");
require_once($__FILEPATH__."../class_def.php");
require_once($__FILEPATH__."../conf/info.php");
require_once("$fckeditorpath");

CheckAdminAndInitHeader();

$id = -1;
if (isset($_GET["id"]))
	$id = intval($_GET["id"]);

$Object = new NewsListItem();
$mysqli = GetMysqliInstance();

if (isset($_POST["update"]))
{
	$ret = false;
	$id = intval($_POST["id"]);
    $title = $_POST["title"];
    $content = $_POST["content"];
	if($title != "" && $content != "")
	{
    	$str = "update newslist set title=?, content=? where id = $id";
		$stmt = $mysqli->prepare($str);
		$stmt->bind_param("ss", $title, $content);
		$ret = $stmt->execute();
        $stmt->close();
    }

    if ($ret)
    	echo "<p style=\"color: green\">更新成功！</p>";    
    else 
    	echo "<p style=\"color:red\">更新失败，所有内容都不能为空</p>";
    $mysqli->close();
	exit(0);
}

$result = $mysqli->query("select * from newslist where id = $id", MYSQLI_USE_RESULT);
if ($result)
{
	if ($row = $result->fetch_array(MYSQLI_ASSOC))
	{
		$Object->id = $row["id"];
		$Object->title = $row["title"];
		$Object->content = $row["content"];
		$Object->user = $row["user"];
		$Object->ip  = $row["ip"];
		$Object->time = $row["time"];
	}

	$result->close();
}

$mysqli->close();

?>